package leetcode.method.dynamic_programming;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class Program322CoinChange {

    public Program322CoinChange() {

    }
    public int coinChange(int[] coins, int amount) {

        int[] dp = new int[amount + 1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int i = 1; i < amount + 1; i++) {
            for (int j = 0; j < coins.length; j++) {
                if (i - coins[j] >= 0) {
                    if (dp[i - coins[j]] == Integer.MAX_VALUE) {
                        continue;
                    }
                    dp[i] = Math.min(dp[i], dp[i - coins[j]] + 1);
                }
            }
        }
        return dp[amount] == Integer.MAX_VALUE ? -1 : dp[amount];
    }

    public static void main(String[] args) {
        Program322CoinChange myStack = new Program322CoinChange();
        int[] coins = {2};
        System.out.println(myStack.coinChange(coins,3));
    }
}
